// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');

const generateTSConfig = (stagedFilenames) => {
  const tsconfig = JSON.parse(fs.readFileSync('tsconfig.json', 'utf8'));
  tsconfig.include = [`${process.cwd()}/src/vite-env.d.ts`, ...stagedFilenames];
  fs.writeFileSync('tsconfig.lint.json', JSON.stringify(tsconfig));

  return 'tsc --noEmit --skipLibCheck --project tsconfig.lint.json';
};

module.exports = {
  './src/**/*.{ts,tsx}': [generateTSConfig],
  // eslint格式化js，jsx代码
  './src/**/*.{js,jsx,ts,tsx}': ['eslint --ext .js,.ts,.jsx,.tsx --fix'],
  // prettier代码风格格式化
  './src/**/*.{js,jsx,ts,tsx,css,md,json}': ['prettier --write  --loglevel warn']
};
